package com.pubinfo.passbook.engine.process.variable.medicine;

import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.service.ruler.InformationService;
import com.pubinfo.passbook.engine.process.variable.VariableProcessor;
import com.pubinfo.passbook.engine.utils.ApplicationContextUilts;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.List;

/**
 * 个人总有效支付
 *
 * @author zhouch
 * @date 2022/1/19 11:19
 */
@Slf4j
public class TotalAvailabilityPaysProcessor extends MedicineVariableProcessor {

    @Override
    public String getName() {
        return "个人总有效支付";
    }

    @Override
    public BigDecimal get(MedicineOnJobOrRetireDTO data) {
        log.info("执行参数处理器: {}", this.getClass().getSimpleName());

        List<PayInformation> payInformations = cache.getPayInformationData();

        //个人有效支付总金额
        BigDecimal totalAvailabilityPays = new BigDecimal(0);

        //不能报销的金额
        BigDecimal noAllowance = new BigDecimal(0);
        //特殊人群
        for (PayInformation payInformation : payInformations) {
            BigDecimal ownPay = payInformation.getOwnPayAmount();
            //个人有效支付=个人现金支付-不能报销的金额
            BigDecimal availabilityPay = ownPay.subtract(noAllowance);
            totalAvailabilityPays = totalAvailabilityPays.add(availabilityPay);
        }

        log.info("参数处理器: {} 结果: {}", this.getClass().getSimpleName(), totalAvailabilityPays);

        outputComputeMessage(totalAvailabilityPays.toString());

        return totalAvailabilityPays;
    }
}
